/**
 * @file 代理设置
 * @author: lvjiran(01395398@sfmail.sf-express.com)
 * @Date: 2021-06-20
 */

const Config = require('./config');

const Util = {
    /**
     * 设置代理
     *
     * @return {Object} 返回文件路径
     */
    setProxy: () => {
        if (!Config.baseURL) {
            return {};
        }

        const { pathname, origin } = new URL(Config.baseURL);

        return {
            [pathname]: {
                target: origin,
                changeOrigin: true,
                pathRewrite: {
                    '^/api': '/'
                }
            }
        };
    }
};

module.exports = Util;
